import service from "@/service";
import md5 from 'js-md5';

const clientId = import.meta.env.VITE_CLIENT_ID;
const authKey = import.meta.env.VITE_AUTH_KEY;
const innerUrl = import.meta.env.VITE_INNER_URL;

/**
 * 获取社区人员统计信息
 * @param {String} tablename  获取数据的表名
 * @param {String} param.begin  获取数据的开始step
 * @param {String} param.end 获取数据的结束step（不包含）
 * @param {String} param.interval 获取数据的间隔 
 * @param {String} param.num_points 折线图数据点数量 point_interval
 * @param {String} param.point_interval 折线图两点间step间隔 
 */
export function getSimStat(tablename, param) {
    return service({
        url: `/sim/stat/${tablename}`,
        method: 'GET',
        params: param
    })
}
/**
 * 获取模拟元信息
 * @param {*} tablename 
 * @returns 
 */
export function getSimMeta(tablename) {
    return service({
        url: `/sim/stat/${tablename}`,
        method: 'GET',
    })
}
/**
 * 人口类型分布
 * @param {*} village 
 * @returns 
 */
export function getPersonCount(village) {
    ///ps/m/social-safety/resident/stastics/type
    let timestamp = Date.now();
    let sign = md5(clientId + authKey + timestamp);
    return service({
        baseURL: `${innerUrl}`,
        url: `/ps/m/social-safety/resident/stastics/type?estate=${village}`,
        method: 'GET',
        headers: {
            clientId: clientId,
            timestamp: timestamp,
            sign: sign
        }
    })
}
/**
 * 人口总览
 * @param {*} village 
 * @returns 
 */
export function getPersonOverview(village) {
    let timestamp = Date.now();
    let sign = md5(clientId + authKey + timestamp);
    return service({
        baseURL: `${innerUrl}`,
        url: `/ps/m/social-safety/resident/stastics/overview?estate=${village}`,
        method: 'GET',
        headers: {
            clientId: clientId,
            timestamp: timestamp,
            sign: sign
        }
    })
}

export function getPersonBuilding(village) {
    let timestamp = Date.now();
    let sign = md5(clientId + authKey + timestamp);
    return service({
        baseURL: `${innerUrl}`,
        url: `/ps/m/social-safety/resident/stastics/building?estate=${village}`,
        method: 'GET',
        headers: {
            clientId: clientId,
            timestamp: timestamp,
            sign: sign
        }
    })
}
/**
 * 查询用户可访问的小区
 */
export function getUserAccessVillage(uid) {
    let timestamp = Date.now();
    let sign = md5(clientId + authKey + timestamp);
    if (uid) {
        return service({
            baseURL: `${innerUrl}`,
            url: `/ps/m/social-safety/estate-region?userId=${uid}`,
            method: 'GET',
            headers: {
                clientId: clientId,
                timestamp: timestamp,
                sign: sign
            }
        })
    }
}
/**
 * 获取平台名称
 * @returns 
 */
export function getTitle() {
    let timestamp = Date.now();
    let sign = md5(clientId + authKey + timestamp);
    return service({
        baseURL: `${innerUrl}`,
        url: `/ps/m/social-safety/title/get`,
        method: 'GET',
        headers: {
            clientId: clientId,
            timestamp: timestamp,
            sign: sign
        }
    })
}
/**
 * 修改平台名称
 * @returns
 */
export function updateTitle(title) {
    let timestamp = Date.now();
    let sign = md5(clientId + authKey + timestamp);
    return service({
        baseURL: `${innerUrl}`,
        url: `/ps/m/social-safety/title/update?title=${title}`,
        method: 'POST',
        headers: {
            clientId: clientId,
            timestamp: timestamp,
            sign: sign
        }
    })
}